package com.example.wanxiang.repository;

import com.example.wanxiang.entity.Article;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ArticleRepository extends MongoRepository<Article, String> {
    @Query("{'title': {$regex: ?0}}")
    List<Article> findByTitleLike(String title);
    @Query("{'title': {$regex: ?0}}")
    Page<Article> getArticleByTitleLike(String title, PageRequest request);

    long countArticleByTitle(String title);

    Optional<Article> findById(String id);
}
